package handler

import (
	"oct16-test/model"

	"github.com/gin-gonic/gin"
)

// 仓库添加

func Add(c *gin.Context) {
	house_name := c.PostForm("house_name")
	house_address := c.PostForm("house_address")

	if house_name == "" || house_address == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "仓库名称、仓库地址不能为空",
		})
		return
	}
	
	house := model.House{
		HouseName:    house_name,
		HouseAddress: house_address,
	}
	err := model.DB.Create(&house).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
